<?php

namespace App\Models;


/**
 * App\Models\Group
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property string $name 分组名称
 * @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Group newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Group query()
 * @method static \Illuminate\Database\Eloquent\Builder|Group whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Group whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Group whereUserId($value)
 * @mixin \Eloquent
 */
class Group extends Base{

    protected $table = 'groups';


    protected $fillable = [
        'id','user_id','name'
    ];

    public $timestamps = false;//关闭自动维护


    /**
     * 获取列表
     * @param int $limit 分页数量
     * @param array $params 条件参数
     * @param array $fields 查询的字段
     * @return mixed
     */
    protected function getList($limit = 10, $params = [], $fields = ['*']){
        $lists = $this->select($fields)
            ->where(function ($query) use ($params) {
                if(isset($params['uid']) && $params['uid']) {
                    $query ->where('user_id',$params['uid']);
                }
            })->orderBy('id', 'asc')->paginate($limit);
        return $lists;
    }


    protected function groups(){
        $groups = $this->select(['id','name'])->get()->toArray();
        return $groups;
    }
}
